const app = getApp();
Page({
  data: {
    mealsList: '',
    USER_ASSETS_NAME: '',//姓名
    USER_ASSETS_IDCARD: '',//身份证
    BANK_ASSETS: '',//资产
    EMPLOYEE_ID: '',//工号
    showView: false,
    yuangong: '',
    USER_REALLY_PHONE: '',//手机号
    UUIDSTRING:'',
  },

  //判断隐藏页面的显示
  onLoad: function (e) {
    console.log(e);
    this.setData({
      mealsList: app.globalData.mealsList,
      UUIDSTRING: app.globalData.UUIDSTRING,

        openid: app.globalData.openid,
        jiami: app.globalData.jiami,
        OPEN_ID: app.globalData.openid,
        session_key: app.globalData.session_key,
  
    });


    console.log(e.data);
    var yuan = e.data
    this.setData({
      yuangong: yuan
    })
    
    console.log(this.data.yuangong);
    console.log(this.data.mealsList);
    // showView: (options.showView == "true" ? true : false)
  },


  //判断输入框是否有数据

  jump: function () {
   
    this.setData({
      mealsList: app.globalData.mealsList,
      UUIDSTRING: app.globalData.UUIDSTRING,
    });

    console.log(this.data.UUIDSTRING);

    if (!this.data.USER_ASSETS_NAME || !this.data.USER_ASSETS_IDCARD || !this.data.mealsList) {
      console.log(this.data.USER_ASSETS_NAME);
      console.log(this.data.USER_ASSETS_IDCARD);
      console.log(this.data.mealsList);
      wx.showModal({
        title: '温馨提示',
        content: '请完善信息',
        success: function (res) {
          if (res.confirm) {//这里是点击了确定以后   
            console.log('用户点击确定')
          } else {//这里是点击了取消以后
            console.log('用户点击取消')
          }
        }
      })

    } else {
      var that = this;
      // 验证白名单
      wx.request({
        url: app.globalData.interface+'/shanyouhui/API_1021_getCouponReallyPhone',
        method: 'GET',
        data: {
          USER_COUPON_PHONE: this.data.USER_ASSETS_IDCARD, //手机号
          USER_ASSETS_NAME:this.data.USER_ASSETS_NAME,
          OPEN_ID: this.data.OPEN_ID, //用户OPEN_ID
          session_key:this.data.session_key,
          OPEN_UUID:this.data.jiami
          
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        // 15829715986
        success: function (res) {
          console.log(res);
          if (res.data.hasOwnProperty('ReallyPhone')) {
            that.setData({
              showView: (!that.data.showView)
            })
          } else {
            wx.showModal({
              title: '温馨提示',
              content: '没在白名单',
              success: function (res) {
                if (res.confirm) {//这里是点击了确定以后
                  console.log('用户点击确定')
                } else {//这里是点击了取消以后
                  console.log('用户点击取消')
                }
              }
            })
          }
        }
      })
    }
  },

  //跳转回去
  quno: function () {
    wx.redirectTo({
      url: '../../pages/djzhuce/djzhuce'
    })
  },


  //点击确定以后向后台传数据
  tjok: function () {
    wx.request({
      url: app.globalData.interface+'/shanyouhui/API_1030_addUserCouponAssets',
      method: 'POST',
      data: {
        USER_COUPON_PHONE: this.data.USER_ASSETS_IDCARD,//手机号
        USER_ASSETS_NAME: this.data.USER_ASSETS_NAME,
        // EMPLOYEE_ID: this.data.mealsList,
        // BANK_ASSETS: this.data.BANK_ASSETS,
        // UUIDSTRING: this.data.UUIDSTRING,
        OPEN_ID: this.data.OPEN_ID, //用户OPEN_ID
        session_key:this.data.session_key,
        OPEN_UUID:this.data.jiami

      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        console.log(res.data);
        if (res.data.result != 'success') {
          wx.showModal({
            title: '温馨提示',
            content: res.data.data,
            success: function (res) {
              if (res.confirm) {//这里是点击了确定以后
                console.log('用户点击确定')
              } else {//这里是点击了取消以后
                console.log('用户点击取消')
              }
            }
          })
        } else {
          wx.showModal({
            title: '温馨提示',
            content: res.data.data,
            success: function (res) {
              if (res.confirm) {//这里是点击了确定以后
                console.log('用户点击确定')
              } else {//这里是点击了取消以后
                console.log('用户点击取消')
              }
            }
          })
        }
      }
    })

  },

  cha_a(){
    wx.navigateTo({
      url: '../../pages/chalu/chalu'
    })
  },


  //验证手机号
  mobileInput(e) {
    let value = e.detail.value.replace(/\D/g, '')
    this.setData({
      mobile: value,
    })
var myreg = /^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(16[0-9]{1})|(19[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
    if (this.data.mobile.length == 0) {
      wx.showToast({
        title: '输入的手机号为空，请重新输入！',
        icon: 'none',
        duration: 1500
      })
      this.setData({
        mobileFormat: false,
      })
    } else if (this.data.mobile.length < 11) {
      
      wx.showToast({
        title: '手机号长度有误，请重新输入！',
        icon: 'none',
        duration: 1500
      })
      this.setData({
        USER_ASSETS_IDCARD:'',
        mobileFormat: false,
      })

    } else if (!myreg.test(this.data.mobile)) {
      wx.showToast({
        title: '手机号有误，请重新输入！',
        icon: 'none',
        duration: 1500
      })
      this.setData({
        USER_ASSETS_IDCARD:'',
        mobileFormat: false,
      })

    } else {
      this.setData({
        mobileFormat: true,
      })
    }
  },





  SHOUYING(e) {
    var that = this
    console.log(e);

    console.log(e.detail.value);

    if (!e.detail.value.replace(/\D/g, '')) {
      that.setData({
        BANK_ASSETS: '',
    
      })
    } else if (e.detail.value > 200 ) {
      that.setData({
        BANK_ASSETS: '',
      })

      wx.showToast({
        title: '输入数字大于200，请重新输入！',
        icon: 'none',
        duration: 1500
      })
    }else {
      let shuliang = e.detail.value
      console.log(shuliang);
      that.setData({
        BANK_ASSETS: shuliang,
      })
      console.log(that.data.BANK_ASSETS);
    }
  },




  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {


  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

    //如果没数据就跳回登录页  

    // if (!this.data.mealsList) {
    //   wx.navigateTo({
    //     url: '../../pages/login/login'
    //   })
    // }

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})